var apiTest = require('hy5b/auto/api-test')
var util = require('../common/util.js');

var _ = require('underscore');
var global = require('../common/global.js')

var hdata = require('hy5b/auto/data')

const severity = ['恢复', '提醒', '错误', '紧急']

module.exports = {
  '/test/html': function(req, res) {
    var html = '<!DOCTYPE html><html><head><script>window.name = "abc";</script></head><body>1729</body></html>';
    util.setHeader(res, 'Content-Type', 'text/html; charset=utf-8');
    res.end(html);
  },
  '/test/run': function(req, res, mapping, options) {
    var runInfo = apiTest.run(options)
    var text = '<dl>';
    text += '<dt>启动命令</dt><dd>' + runInfo.cmd + '</dd>';
    text += '<dt>进程PID</dt><dd>' + runInfo.pid + '</dd>';
    text += '<dt>系统启动时间</dt><dd>' + runInfo.startTime + '</dd>';
    text += '<dt>系统运行时间</dt><dd>' + runInfo.runTime + '</dd>';
    text += '</dl>';
    return text;
    res.end(text);
  },
  '/test/get': function(req, res) {
    var data = apiTest.get(global.get());
    util.outJson(req, res, data);
  },
  '/test/xbb': function(req, res) {
    var data = apiTest.xbb();
    util.outJson(req, res, data);
  },
  '/test/business': function(req, res) {
    util.outJson(req, res, hdata.business.data)
  },
  '/test/gis': function(req, res) {
    var data = apiTest.gis();
    util.outJson(req, res, data);
  },
  '/test/val': function(req, res) {
    util.outJson(req, res, {
      data:[{
        a: _.random(500, 1500),
        severityC: severity[0]
      }/*, {
        a: _.random(121581, 142667),
        severityC: severity[1]
      }, {
        a: _.random(121581, 142667),
        severityC: severity[2]
      }, {
        a: _.random(121581, 142667),
        severityC: severity[3]
      }*/]
    });
  }
};
